package com.custom.base.dialog

import android.view.View
import android.widget.ListView
import android.widget.TextView
import com.custom.base.R
import com.custom.base.adapter.SDSimpleTextAdapter
import com.custom.base.base.BaseSDAdapter
import com.custom.base.manager.SDActivityManager
import com.custom.base.util.SDViewUtil

/**
 * 作者：
 * 时间：2021/1/14
 * 描述：选择列表
 */
class SDDialogTvMenu(
    title:String = "",
    cancel:String = "取消",
    tvs:MutableList<String>,
    colors:MutableList<Int> = mutableListOf(),
    listener:OnMenuListener? = null
) :SDDialogBase(){
    init {
        val mView = SDActivityManager.instance.lastActivity?.let { SDViewUtil.getRId(it, R.layout.dialog_menu) }
        val mTvTitle = mView?.findViewById(R.id.dialog_menu_tv_title) as TextView
        val mTvCancel = mView.findViewById(R.id.dialog_menu_tv_cancel) as TextView
        val listView = mView.findViewById(R.id.dialog_menu_lv_listView) as ListView

        if(title == "") mTvTitle.visibility = View.GONE
        else mTvTitle.text = title
        mTvCancel.text = cancel

        mTvCancel.setOnClickListener {
            dismissClick()
        }

        val adapter = SDSimpleTextAdapter(tvs,color = colors)
        adapter.setListenerItemClick(object :BaseSDAdapter.ItemClickListener<String>{
            override fun onClick(position: Int, item: String, view: View?) {
                listener?.onClickItem(position,item)
                dismissClick()
            }
        })
        listView.adapter = adapter

        setDialogView(mView)
        setOnTouchOutside(true)
    }

    interface OnMenuListener{
        fun onClickItem(index:Int,str:String)
    }
}